<?
/**
 * @author battlej@nyaha.net
 * @version 1.0
 */

	require_once 'PHPUnit\Framework\TestCase.php';

	include_once dirname(__FILE__).'/class/Database.php';
	include_once dirname(__FILE__).'/class/Search.php';
	include_once dirname(__FILE__).'/class/Page.php';

	class SqliteTest extends PHPUnit_Framework_TestCase {
		protected function setUp() {
			$this->table = 'testtable';
			$db = new Database();
			$this->db = $db;
			$this->conn = $db->Connect('rtm.sqlite3.db', '0666', 'id', 'pw', 'sqlite3');

			$this->assertInternalType('resource', $this->conn);

			$qry = "create table ".$this->table." (
						'idx' int(11) NOT NULL ,
						'int_type' int(11) default NULL,
						'char_type' varchar(255)  default NULL,
						'date_type' datetime default NULL
					)
			";

			$r = $db->Query($qry);

			$this->assertInternalType('resource', $r);

		}

		public function testSelect() {
			$db = $this->db;

			$db->Begin();
			for($i=1;$i<=10;$i++) {
				$qry = 'insert into '.$this->table.' ( idx , int_type , char_type , date_type ) values ( '.$i.', 123, "charvalue", date() )';
				$r = $db->Query($qry);
				$this->assertInternalType('resource', $r);
			}
			$db->Commit();

			$qry = new Query();
			$qry->db = 'sqlite3';
			$qry->setTable($this->table);
			$_r = $db->Query($qry->SelectQuery());
			$i = 0;
			while($_d=$db->Fetch($_r)) {
				$i++;
			}
			$this->assertEquals($i, 1);
		}

		protected function tearDown() {
			$this->db->Query('drop table '.$this->table);
		}
	}

	//include_once dirname(__FILE__).'/dbconfig.php';

?>